var nodemailer = require('nodemailer');

// Create a SMTP transport object
//function SmtpTransport(mail) {};

function Smtp() {};

module.exports = Smtp;

Smtp.send = function send(user,type, callback){
    var transport = nodemailer.createTransport("SMTP", {
        //service: 'Gmail', // use well known service.
        // If you are using @gmail.com address, then you don't
        // even have to define the service name
        service : 'Gmail',
        auth: {
            user: "umlonweb@gmail.com",
            pass: "stigmergy"
        }
    });

    console.log('SMTP Configured');

// Message object
    var message = {

        // sender info
        from: 'umlonweb@gmail.com <umlonweb@gmail.com>',
        // Comma separated list of recipients
        //to: '"jiangsfls@163.com" <jiangsfls@163.com>',
        to: '"'+ user.mail +'"' + '<' + user.mail + '>',
        //mail如何使用?????
        // Subject of the message
        subject: 'Test - Link of 激活账号 _ UML On Web', //

        headers: {
            'X-Laziness-level': 1000
        },

        // plaintext body
        text: 'Hello to myself!',

        // HTML body
        html:'<p><b>账户确认：</b><br/></p>'+
            '<p>用户' + user.mail + '您好！<br/></p>'+
            '<p>点击下方链接进行账户激活：<br/></p>'+
            '<p>http://localhost:3000/'+type+'/'+user.mail+'/'+ user.link+'<br/></p>'
    };
    console.log(message.to);
    console.log('Sending Mail');
    transport.sendMail(message, function(error){
        if(error){
            console.log('Error occured');
            console.log(error.message);
            return;
        }
        console.log('Message sent successfully!');
    });

    callback(null);
};
